package com.fhz.day009;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

/**
 * 时间:2022/4/28
 *
 * @author msfeng
 * 简述: TODO
 */
public class MyPervider extends ContentProvider {

    private MyOpenHelper myOpenHelper;
    private SQLiteDatabase db;

    @Override
    public boolean onCreate() {
        myOpenHelper = new MyOpenHelper(getContext(), "school.db", null, 1);
        db = myOpenHelper.getReadableDatabase();
        if(db != null){
            return true;
        }
        return false;
    }

    @Nullable
    @Override
    public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
        Cursor query = db.query("user",projection,selection,selectionArgs,null,null,sortOrder);
        return query;
    }

    @Nullable
    @Override
    public String getType(@NonNull Uri uri) {
        String authority = uri.getAuthority();
        return null;
    }

    @Nullable
    @Override
    public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
        db.insert("user",null,values);
        return uri;
    }

    @Override
    public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) {
        int user = db.delete("user", selection, selectionArgs);
        return user;
    }

    @Override
    public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) {
        return db.update("user",values,selection,selectionArgs);
    }
}

